package br.com.advance.automacao.model;

import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import br.com.advance.automacao.enumeration.Fabricante;

@Entity
@Table(name = "CLP")
@NamedQueries({@NamedQuery(name=CLP.BUSCAR_TODOS_ATIVOS, query="select c from CLP c WHERE c.ativo = 1 "),
	@NamedQuery(name=CLP.BUSCAR_TODOS_ATIVOS_COM_ERROS, query="select distinct c from CLP c LEFT JOIN FETCH c.erros e WHERE c.ativo = 1 "),
	@NamedQuery(name=CLP.BUSCAR_POR_NOME, query="select distinct c from CLP c WHERE c.nome = :nome "),
	@NamedQuery(name=CLP.BUSCAR_POR_IP, query="select distinct c from CLP c WHERE c.ip = :ip "),
	@NamedQuery(name=CLP.BUSCAR_POR_ID_COM_ERROS, query="select distinct c from CLP c join fetch c.erros e WHERE c.id = :id ")})
public class CLP {

	public static final String BUSCAR_TODOS_ATIVOS = "CLP.buscarTodosAtivos";
	public static final String BUSCAR_POR_NOME = "CLP.buscarPorNome";
	public static final String BUSCAR_POR_IP = "CLP.buscarPorIp";
	public static final String BUSCAR_POR_ID_COM_ERROS = "CLP.buscarPorIdComErros";
	public static final String BUSCAR_TODOS_ATIVOS_COM_ERROS = "CLP.buscarTodosAtivosComErrosPossiveis";

	@Id
    @Column(name = "ID")
	@GeneratedValue
	private Long id;

	@Column(name = "IP", nullable=false, length=15, columnDefinition="VARCHAR")
	private String ip;

	@Column(name = "NOME", nullable=false, length=15, columnDefinition="VARCHAR")
	private String nome;

	@Column(name = "ATIVO", nullable=false, columnDefinition="BIT")
	private Boolean ativo;

	@OneToMany(mappedBy="clp", fetch=FetchType.LAZY)
	private List<Erro> erros;

	@OneToMany(mappedBy="clp", fetch=FetchType.LAZY)
	private List<Evento> eventos;

	@Column(name = "FABRICANTE", nullable=false, length=1, columnDefinition="VARCHAR")
	@Enumerated(value=EnumType.STRING)
	private Fabricante fabricante;

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getIp() {
		return ip;
	}

	public void setIp(String ip) {
		this.ip = ip;
	}

	public Boolean getAtivo() {
		return ativo;
	}

	public void setAtivo(Boolean ativo) {
		this.ativo = ativo;
	}

	public List<Erro> getErros() {
		return erros;
	}

	public void setErros(List<Erro> erros) {
		this.erros = erros;
	}

	public List<Evento> getEventos() {
		return eventos;
	}

	public void setEventos(List<Evento> eventos) {
		this.eventos = eventos;
	}

	public String getNome() {
		return nome;
	}

	public void setNome(String nome) {
		this.nome = nome;
	}

	public Fabricante getFabricante() {
		return fabricante;
	}

	public void setFabricante(Fabricante fabricante) {
		this.fabricante = fabricante;
	}

}
